package com.happyfamily.springboot.crowdsourcingplatform.controller.wang;

import com.happyfamily.springboot.crowdsourcingplatform.annotation.OperationLogDetail;
import com.happyfamily.springboot.crowdsourcingplatform.base.result.PageTableRequest;
import com.happyfamily.springboot.crowdsourcingplatform.base.result.Results;
import com.happyfamily.springboot.crowdsourcingplatform.enums.OperationType;
import com.happyfamily.springboot.crowdsourcingplatform.enums.OperationUnit;
import com.happyfamily.springboot.crowdsourcingplatform.model.Exposure;
import com.happyfamily.springboot.crowdsourcingplatform.model.Orders;
import com.happyfamily.springboot.crowdsourcingplatform.service.wang.ExposureService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 曝光台的控制类
 */
@Controller
@Slf4j
public class ExposureController
{
	@Autowired
	private ExposureService exposureServiceImpl;

	/**
	 * 前端曝光台显示轮播
	 * @return
	 */
	@ApiOperation(value = "前端曝光台显示轮播", notes = "前端曝光台显示轮播")
	@OperationLogDetail(detail = "前端曝光台显示轮播", level = 1, operationUnit = OperationUnit.SYSTEM, operationType = OperationType.SELECT)
	@GetMapping("/exposure/list")
	@ResponseBody
	public List<Exposure> exposureList()
	{
		return exposureServiceImpl.findExposure();
	}

	/**
	 * 前端查看更多曝光
	 * @param request
	 * @param who
	 * @param starttime
	 * @param endtime
	 * @param exposureSticky
	 * @return
	 */
	@ApiOperation(value = "前端查看更多曝光", notes = "前端查看更多曝光")
	@OperationLogDetail(detail = "前端查看更多曝光", level = 1, operationUnit = OperationUnit.USER, operationType = OperationType.SELECT)
	@RequestMapping("/exposure/findExposureList")
	@ResponseBody
	public Results<Exposure> findExposureList(PageTableRequest request, String who, String starttime, String endtime, String exposureSticky)
	{
		request.countOffset();
		return exposureServiceImpl.findExposureList(request.getOffset(), request.getLimit(), who, starttime, endtime, exposureSticky);
	}

	/**
	 * 后端曝光台管理
	 * @param request
	 * @param who
	 * @param starttime
	 * @param endtime
	 * @param exposureType
	 * @param exposureSticky
	 * @return
	 */
	@PreAuthorize("hasAnyAuthority('back:exposure:query')")
	@ApiOperation(value = "后端曝光台管理表格", notes = "后端曝光台管理表格")
	@OperationLogDetail(detail = "后端曝光台管理表格", level = 1, operationUnit = OperationUnit.ADMIN, operationType = OperationType.SELECT)
	@RequestMapping("/api-back/exposure/exposureDeploy")
	@ResponseBody
	public Results<Exposure> exposureDeploy(PageTableRequest request, String who, String starttime, String endtime, String exposureType, String exposureSticky)
	{
		request.countOffset();
		return exposureServiceImpl.exposureDeploy(request.getOffset(), request.getLimit(), who, starttime, endtime, exposureType, exposureSticky);
	}

	/**
	 * 管理员对曝光删除的操作
	 * @param eid
	 * @return
	 */
	@PreAuthorize("hasAnyAuthority('back:exposure:delete')")
	@ApiOperation(value = "管理员对曝光删除的操作", notes = "管理员对曝光删除的操作")
	@OperationLogDetail(detail = "管理员对曝光删除的操作", level = 4, operationUnit = OperationUnit.ADMIN, operationType = OperationType.DELETE)
	@PostMapping("/api-back/exposure/exposure-delete")
	@ResponseBody
	public String exposureDelete(String eid)
	{
		return exposureServiceImpl.exposureDelete(eid);
	}

	/**
	 * 管理员对曝光取消置顶的操作
	 * @param eid
	 * @return
	 */
	@PreAuthorize("hasAnyAuthority('back:exposure:cancelSticky')")
	@ApiOperation(value = "管理员对曝光取消置顶的操作", notes = "管理员对曝光取消置顶的操作")
	@OperationLogDetail(detail = "管理员对曝光取消置顶的操作", level = 2, operationUnit = OperationUnit.ADMIN, operationType = OperationType.UPDATE)
	@PostMapping("/api-back/exposure/exposure-cancelSticky")
	@ResponseBody
	public String exposureCancelSticky(String eid)
	{
		return exposureServiceImpl.exposureSticky(eid, "0");
	}

	/**
	 * 管理员对曝光置顶的操作
	 * @param eid
	 * @return
	 */
	@PreAuthorize("hasAnyAuthority('back:exposure:doSticky')")
	@ApiOperation(value = "管理员对曝光置顶的操作", notes = "管理员对曝光置顶的操作")
	@OperationLogDetail(detail = "管理员对曝光置顶的操作", level = 2, operationUnit = OperationUnit.ADMIN, operationType = OperationType.UPDATE)
	@PostMapping("/api-back/exposure/exposure-doSticky")
	@ResponseBody
	public String exposureDoSticky(String eid)
	{
		return exposureServiceImpl.exposureSticky(eid, "1");
	}

	/**
	 * 管理员对曝光审核通过的操作
	 *
	 * @param eid
	 * @param oid
	 * @return
	 */
	@PreAuthorize("hasAnyAuthority('back:exposure:yes')")
	@ApiOperation(value = "管理员对曝光审核通过的操作", notes = "管理员对曝光审核通过的操作")
	@OperationLogDetail(detail = "管理员对曝光审核通过的操作", level = 2, operationUnit = OperationUnit.ADMIN, operationType = OperationType.UPDATE)
	@PostMapping("/api-back/exposure/exposure-yes")
	@ResponseBody
	public String exposureYes(String eid, String oid)
	{
		return exposureServiceImpl.exposureYes(eid, oid);
	}

	/**
	 * 管理员对曝光审核   不通过的操作
	 *
	 * @param eid
	 * @param oid
	 * @return
	 */
	@PreAuthorize("hasAnyAuthority('back:exposure:no')")
	@ApiOperation(value = "管理员对曝光审核不通过的操作", notes = "管理员对曝光审核不通过的操作")
	@OperationLogDetail(detail = "管理员对曝光审核不通过的操作", level = 2, operationUnit = OperationUnit.ADMIN, operationType = OperationType.UPDATE)
	@PostMapping("/api-back/exposure/exposure-no")
	@ResponseBody
	public String exposureNo(String eid, String oid)
	{
		return exposureServiceImpl.exposureNo(eid, oid);
	}

	/**
	 * 管理员对仲裁查看订单详情
	 *
	 * @param oid
	 * @return
	 */
	@PreAuthorize("hasAnyAuthority('back:exposure:details')")
	@ApiOperation(value = "管理员对仲裁查看订单详情", notes = "管理员对仲裁查看订单详情")
	@OperationLogDetail(detail = "管理员对仲裁查看订单详情", level = 1, operationUnit = OperationUnit.ADMIN, operationType = OperationType.SELECT)
	@PostMapping("/api-back/exposure/exposure-details")
	@ResponseBody
	public Orders exposureDetails(String oid)
	{
		return exposureServiceImpl.exposureDetails(oid);
	}

	/**
	 * 跳转查看更多曝光窗口
	 *
	 * @return
	 */
	@ApiOperation(value = "跳转查看更多曝光窗口", notes = "跳转查看更多曝光窗口")
	@GetMapping("/exposure/moreExposure")
	public String moreExposure()
	{
		return "frontPage/exposure-list";
	}

}
